﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BL.Entity;
using BL.Service;

namespace LTO
{
    /// <summary>
    /// Interaction logic for deleteNUm.xaml
    /// </summary>
    public partial class deleteNUm : Window
    {
        public List<ShowNumberDTO> curentNum { get; set; }
        string numtype;
        public deleteNUm()
        {
            InitializeComponent();
         
        }
        
        public deleteNUm(List<ShowNumberDTO> number,string numType)
        {
            InitializeComponent();
            curentNum = new List<ShowNumberDTO>();
            curentNum = number;
            numtype = numType;
           
            textBox1.Focus();
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text.Trim()))
            {
                if (e.Key == Key.Enter)
                {
                    tbl_NumberServer Numberservice = new tbl_NumberServer();

                   
                     try
                        {
                            
                            decimal dele = decimal.Parse(textBox2.Text);
                            if (numtype == BL.Enum.NumberType.FourNumber && textBox1.Text.Replace("*","").ToString().Trim().Length==5)
                            {
                                numtype = BL.Enum.NumberType.FiveNumber;
                            }
                            Numberservice.Addnumber(textBox1.Text.Trim(), dele, 0, 0, Gobalsource.UserNameLogin, numtype, true);
                        }
                        catch (Exception ex)
                        {

                            MessageBox.Show(ex.Message,"",MessageBoxButton.OK);
                            (Owner as Window).Activate();
                        }

                        try
                        {
                            (Owner as _listbox).GetNumberShow();
                            (Owner as _listbox).RegisterDelete();
                            (Owner as _listbox).Activate();
                            this.Close();
                        }
                        catch (Exception)
                        {


                        }
                        try
                        {
                            (Owner as ViewOver1).GetNumberShow();
                            (Owner as ViewOver1).RegisterDelete();
                            (Owner as ViewOver1).Activate();
                            this.Close();
                        }
                        catch (Exception)
                        {


                        }
                        try
                        {
                            (Owner as viewTodGroup).GetNumberShow();
                            (Owner as viewTodGroup).RegisterDelete();
                            (Owner as viewTodGroup).Activate();
                            this.Close();
                        }
                        catch (Exception)
                        {


                        }
                        try
                        {
                            (Owner as viewUnder1).GetNumberShow();
                            (Owner as viewUnder1).RegisterDelete();
                            (Owner as viewUnder1).Activate();
                            this.Close();
                        }
                        catch (Exception)
                        {


                        }
                        try
                        {
                            (Owner as viewFourNumber).GetNumberShow();
                            (Owner as viewFourNumber).RegisterDelete();
                            (Owner as viewFourNumber).Activate();
                            this.Close();
                        }
                        catch (Exception)
                        {


                        }
                        
                    
                }
            }
        }

        private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter) {
                textBox2.Focus();
            }
        }
    }
}
